﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ChoViet.Model;
using ChoViet.Lib.Common;
using System.Text;
using ChoViet.Site.Properties;

namespace ChoViet.Site.Controllers
{
    public class AjaxDataController : Controller
    {
        //
        // GET: /AjaxData/

        ChoVietDataContext eDataContext = new ChoVietDataContext();
        //
        // GET: /AjaxData/Departments/1
        /*
        public JsonResult AddQuestion()
        {
            try
            {
                eDataContext.DeferredLoadingEnabled = false;
                Question q = new Question();
                q.AddDate = DateTime.Now;
                q.CatID = Utils.ParseInt(Request["catid"]);
                q.Name = Request["name"];
                q.PubYN = false;
                q.QContent = Request["content"];
                q.RContent = string.Empty;
                q.SendBy = Request["sendname"];
                q.SendDate = DateTime.Now;
                q.SendEmail = Request["sendemail"];
                q.SendPhone = Request["sendphone"];
                eDataContext.Questions.InsertOnSubmit(q);
                eDataContext.SubmitChanges();
                return Json(q, JsonRequestBehavior.AllowGet);
            }
            catch
            {
                return Json("", JsonRequestBehavior.AllowGet);
            }
        }
         */ 
        public ContentResult AddEmail()
        {
            try
            {
                var mailBody = new StringBuilder();
                mailBody.Append("Thông tin người gửi:");
                mailBody.Append("<br />");
                mailBody.Append("<strong>Họ và tên: </strong>");
                mailBody.Append(Request["name"]);
                mailBody.Append("<br />");
                mailBody.Append("<strong>Email: </strong>");
                mailBody.Append(Request["email"]);
                mailBody.Append("<br />");
                mailBody.Append("<br />");
                mailBody.Append("<strong>Tiêu đề: </strong>");
                mailBody.Append(Request["subject"]);
                mailBody.Append("<br />");
                mailBody.Append("<strong>Nôi dung: </strong>");
                mailBody.Append("<br />");
                mailBody.Append(Request["body"]);
                List<string> listMail = new List<string>();
                listMail.Add(Request["remail1"]);
                listMail.Add(Request["remail2"]);
                listMail.Add(Request["remail3"]);
                try
                {
                   // SmtpMailer.sendMail(listMail, Request["email"], "Bạn có một Email liên hệ gửi từ hệ thống website PV OIL HÀ NỘI", mailBody.ToString());
                }
                catch (Exception exp)
                {

                }

            }
            catch (Exception exp)
            {
                ErrorLog.WriteLog(exp);
            }
            return Content(string.Empty);
        }

        public ActionResult ChangeLanguage(int id)
        {
            if (id > 0)
            {
                Session.Remove("LanguageID");
                Session["LanguageID"] = id.ToString();
            }
            return View();
        }
    }
}
